package com.lagou.edu.serivce.impl;

import com.lagou.service.ISendEmailService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;

@Service
public class SendEmailServiceImpl implements ISendEmailService {

    @Autowired
    private JavaMailSender javaMailSender;

    @Override
    public boolean sendCode(String email, String code) {
        try{
//            MailUtil.send(email, "邮箱验证码", code, false);
            SimpleMailMessage message = new SimpleMailMessage();
            message.setSubject("注册验证码");
            message.setText(code);
            message.setTo(email);
            message.setFrom("wangyue198901@sina.com");
            javaMailSender.send(message);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }
}
